import {request} from "@/network/request-config";
import {uploadFileAPI} from "@/network/upload-file";

export function getEmploymentByStudentIdAPI(data){
    return request({
        url:"/hems/employment/query/"+ data,
        method:"get",
    }).then(res=>{
        return res
    })
}

export function addStudentEmploymentAPI(data){
    const formData = new FormData();
    formData.append('file', data.offer.raw, data.offer.name);
    return uploadFileAPI(formData,"offer").then(res=>{
        if (res.data.code === 0){
            data.offer = res.data.data.url
            return request({
                url:"/hems/employment/add",
                method:"post",
                data
            }).then(res=>{
                return res
            })
        }
        else {
            return res
        }
    })
}

export function updateStudentEmploymentAPI(data, updateFile){
    if (updateFile){
        const formData = new FormData();
        formData.append('file', data.offer.raw, data.offer.name);
        return uploadFileAPI(formData,"offer").then(res=>{
            if (res.data.code === 0){
                data.offer = res.data.data.url
                data.offerUrl = res.data.data.url
                return request({
                    url:"/hems/employment/mod",
                    method:"post",
                    data
                }).then(res=>{
                    return res
                })
            }
            else {
                return res
            }
        })
    }
    else{
        return request({
            url:"/hems/employment/mod",
            method:"post",
            data
        }).then(res=>{
            return res
        })
    }
}